<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>在线实验名称：</p>
                                <input type="text" name="onlineExperimentName"/>
                            </li>
                            <li>
                                <p>在线实验网址：</p>
                                <input type="text" name="onlineExperimentUrl"/>
                            </li>
                            <li>
                                <p>专业：</p>
                                <div class="col-sm-8">
                                    <!--<input name="profession" th:field="*{profession}" class="form-control" type="text">-->
                                    <select name="profession" id="profession" th:with="dicts=${@dict.getType('sys_profession')}">
                                        <option value="">请选择</option>
                                        <option th:each="dict:${dicts}" th:value="${dict.dictValue}" th:text="${dict.dictLabel}"></option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:onlineExperiment:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:onlineExperiment:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:onlineExperiment:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:onlineExperiment:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:onlineExperiment:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:onlineExperiment:remove')}]];
        var prefix = ctx + "system/onlineExperiment";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "【虚拟实验】",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'onlineExperimentId', 
                    title : '在线实验id',
                    visible: false
                },
                {
                    field : 'onlineExperimentName', 
                    title : '在线实验名称'
                },
                {
                    field : 'onlineExperimentUrl', 
                    title : '在线实验网址'
                },
                {
                    field : 'professionName',
                    title : '专业'
                },
                    {
                        /*field:"ifOpen",
                       title:"是否开放实验" ,
                       formatter : function (value,row,index) {
                            //开放
                            if(value==1){
                                return "<div class=\"col-sm-9\">\n" +
                                    "    <label class=\"toggle-switch switch-solid\">\n" +
                                    "        <input type=\"checkbox\" id=\"status\" value="+row.onlineExperimentId+",1 checked onchange='changeStatus(this.value)'> <span></span>\n" +
                                    "    </label>\n" +
                                    "</div>";
                            }else {
                                return "<div class=\"col-sm-9\">\n" +
                                    "    <label class=\"toggle-switch switch-solid\">\n" +
                                    "        <input type=\"checkbox\" id=\"status\" value="+row.onlineExperimentId+",2 onchange='changeStatus(this.value)'> <span></span>\n" +
                                    "    </label>\n" +
                                    "</div>";
                            }
                       }*/
                        visible: editFlag == 'hidden' ? false : true,
                        title: '是否开放实验',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return statusTools(row);
                        }
                    },
                {
                    field : 'assignTeacherName',
                    title : '指派给教师姓名',
                    formatter : function(value,row,index){
                        if(value==null || value==''){
                            return "无";
                        }else{
                            return value;
                        }
                    }
                },
                {
                    field : 'assignTeacher',
                    title : '指派状态',
                    formatter : function (value,row,index) {
                        if(value==null || value==''){
                            return "<input type='button' value='未指派' class='btn btn-danger'/>";
                        }else{
                            return "<input type='button' value='已指派' class='btn btn-primary'/>";
                        }
                    }
                },
                {
                     title : '答疑',
                     formatter : function (value,row,index) {
                         var actions = [];
                         actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="answer(\'' + row.onlineExperimentId + '\')"><i class="fa fa-edit"></i>答疑回复</a> ');
                         return actions.join('');
                     }
                 },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.onlineExperimentId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.onlineExperimentId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="assign(\'' + row.onlineExperimentId + '\')"><i class="fa fa-edit"></i>指派教师</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function assign(value) {
            //获取到当前试验的信息
            //window.location.href=prefix+'/assign/'+value;
            $.modal.open("指派教师页面",prefix+'/assign/'+value);
        }

        /* 实验开放的状态 */
        function statusTools(row) {
            if (row.ifOpen == 2) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" ></i> ';  /*onclick="enable(\'' + row.onlineExperimentId + ',' +row.assignTeacher+'\')"*/
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" ></i> ';  /*onclick="disable(\'' + row.onlineExperimentId + '\')"*/
            }
        }


        /* 实验关闭 */
        function disable(value) {
            $.modal.confirm("确认要关闭实验？", function() {
                $.operate.post(prefix + "/edit", { "onlineExperimentId": value, "ifOpen": 2 });
            })
        }

        /* 实验开放 */
        function enable(value) {
            //if()
            $.modal.confirm("确认要开放实验？", function() {
                $.operate.post(prefix + "/edit", { "onlineExperimentId": value, "ifOpen": 1 });
            })
        }

        /**
         * 回复学生的问题
         */
        function answer(value){
            window.location.href = ctx + "/system/question/look2?experimentId="+value;
        }
    </script>
</body>
</html>